/***************************************************************
File Name: [!output PROJECT_NAME].cpp
Author: [!output AuthorName]
Date: [!output CurrentDate]
****************************************************************/
#include "lcstr.h"
#include "sysdllFun.h"
#include "encoder.h"
int coder(void * pdata);
void WinMainCRTStartup(void)
{
	//for Debug
//int a =1;
//int b =2;
	//int c = a+b;
	
	IMAGE_DOS_HEADER * pKernel32 = (IMAGE_DOS_HEADER*)GetKernel32Address();
//	coder((void *)0xf0f0f0f0);
}

int decoder(void *pdata)
{
	codedata * pCode = (codedata *)pdata;
	decoder((char *)((char *)pdata+1),pCode->nLen);
	FunGetModuleHandleA fun = (FunGetModuleHandleA)GetGetModuleHandleA();
	for (int i =0;i<pCode->seccount;i++)
	{
		decoder((char *)(pCode->sec[i].coderva+(DWORD)fun(NULL)),pCode->sec[i].codenLen);
	}
	return 0;
}

int coder(void * pdata)
{
//	FunLocalAlloc  fun = (FunLocalAlloc )GetLocalAlloc();
//	char * pcode = (char *)fun(LPTR,16);
//	if (pcode)
	{
//		char szdata[100] = {0};
//		FunMessageBoxA fun3 = (FunMessageBoxA)GetMessageBoxAddress();
//		fun3(NULL,szdata,szdata,MB_OK);
		decoder(pdata);
	}
	DWORD oep = ((codedata*)pdata)->oep;
	_asm{
		mov ecx, DWORD ptr[oep];
		mov eax, DWORD ptr[pdata];
		mov eax, DWORD ptr[eax];
		mov DWORD ptr[pdata],ecx;
		POP ECX
		XOR EAX,EAX
		POP ESI
		MOV ESP,EBP
		POP EBP
		POP ECX
		retn;
			

//		pop eax;
	//	pop eax;
	}
	return 0;
}
